//
//  MemberView.m
//  quxiangtao
//
//  Created by xbmios on 2018/7/25.
//  Copyright © 2018年 shanhaijin. All rights reserved.
//

#import "MemberView.h"
#import "BuyMemberViewController.h"

#define Colorebebeb [UIColor colorWithHexString:@"ebebeb"]

@interface MemberView ()
@property (strong, nonatomic) UIView *topLine;

@property (strong, nonatomic) UIImageView *memberIV;

@property (strong, nonatomic) UILabel *desL;

@property (strong, nonatomic) UIView *immediateOpenUpView;
@property (strong, nonatomic) UILabel *immediateL;
@property (strong, nonatomic) UIImageView *arrowIV;

@property (strong, nonatomic) UIView *lineV;

@end

@implementation MemberView

- (instancetype)init {
    
    if (self = [super init]) {
        
        self.backgroundColor = Colorf7f7f7;
        
        [self addSubview:self.topLine];
        [self addSubview:self.memberIV];
        [self addSubview:self.desL];
        [self addSubview:self.immediateOpenUpView];
        [self.immediateOpenUpView addSubview:self.immediateL];
        [self.immediateOpenUpView addSubview:self.arrowIV];
        [self addSubview:self.lineV];

    }
    
    return self;
    
}
#pragma mark -开通会员点击事件
- (void)openUpClick:(UIGestureRecognizer *)recognizer {
    return;
    NSLog(@"开通会员");
    
    BuyMemberViewController *vc = [[BuyMemberViewController alloc] init];
    [self.parentVC.navigationController pushViewController:vc animated:YES];
    
}

- (void)layoutSubviews {
    
    [super layoutSubviews];
    __weak typeof(self) weakSelf = self;
    
    [self.topLine mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.mas_left);
        make.right.mas_equalTo(weakSelf.mas_right);
        make.bottom.mas_equalTo(weakSelf.mas_bottom);
        make.height.mas_equalTo(jisuan(1));
    }];
    
    [self.memberIV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.mas_left).with.offset(jisuan(20));
        make.centerY.mas_equalTo(weakSelf.mas_centerY);
        make.width.mas_equalTo(jisuan(80));
        make.height.mas_equalTo(jisuan(30));
        
    }];
    [self.desL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.memberIV.mas_right).with.offset(jisuan(16));
        make.centerY.mas_equalTo(weakSelf.mas_centerY);
    }];
    [self.immediateOpenUpView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(weakSelf.mas_right);
        make.top.mas_equalTo(weakSelf.mas_top);
        make.bottom.mas_equalTo(weakSelf.mas_bottom);
        make.width.mas_equalTo(jisuan(200));
    }];
    [self.immediateL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.immediateOpenUpView.mas_left).with.offset(jisuan(30));
        make.centerY.mas_equalTo(weakSelf.immediateOpenUpView.mas_centerY);

    }];
    [self.arrowIV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(weakSelf.immediateOpenUpView.mas_right).with.offset(-jisuan(30));
        make.centerY.mas_equalTo(weakSelf.immediateOpenUpView.mas_centerY);
        make.width.mas_equalTo(jisuan(12));
        make.height.mas_equalTo(jisuan(20));
    }];
    [self.lineV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.mas_left);
        make.right.mas_equalTo(weakSelf.mas_right);
        make.bottom.mas_equalTo(weakSelf.mas_bottom);
        make.height.mas_equalTo(jisuan(1));
        
    }];
}

#pragma mark -lazy

- (UIView *)topLine {
    
    if (!_topLine) {
        
        _topLine = [[UIView alloc] init];
        _topLine.backgroundColor = Colordddddd;
        
    }
    return _topLine;
}

- (UIImageView *)memberIV {
    
    if (!_memberIV) {
        
        _memberIV = [[UIImageView alloc] init];
        _memberIV.contentMode = UIViewContentModeScaleAspectFit;
        _memberIV.image = [UIImage imageNamed:@"superMenberbg"];
    }
    
    return _memberIV;
}

- (UILabel *)desL {
    
    if (!_desL) {
        
        _desL = [[UILabel alloc] init];
        _desL.font = Font(24);
        _desL.textAlignment = NSTextAlignmentLeft;
    
        NSString *str = @"开通超级VIP10可以享受100%积分抵扣";
        NSMutableAttributedString *attributeStr = [[NSMutableAttributedString alloc] initWithString:str];
        [attributeStr addAttribute:NSForegroundColorAttributeName value:Color333333 range:NSMakeRange(0, 2)];
        [attributeStr addAttribute:NSForegroundColorAttributeName value:Colorff0000 range:NSMakeRange(2, 7)];
        [attributeStr addAttribute:NSForegroundColorAttributeName value:Color333333 range:NSMakeRange(9, 4)];
        [attributeStr addAttribute:NSForegroundColorAttributeName value:Colorff0000 range:NSMakeRange(13, 4)];
        [attributeStr addAttribute:NSForegroundColorAttributeName value:Color333333 range:NSMakeRange(17, str.length - 17)];
        _desL.attributedText = attributeStr;
        
    }
    
    return _desL;
}

- (UIView *)immediateOpenUpView {
    
    if (!_immediateOpenUpView) {
        
        _immediateOpenUpView = [[UIView alloc] init];
        _immediateOpenUpView.backgroundColor = Colorebebeb;
        
        UITapGestureRecognizer *openUpV = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(openUpClick:)];
        [_immediateOpenUpView addGestureRecognizer:openUpV];

        
    }
    return _immediateOpenUpView;
}

- (UILabel *)immediateL {
    
    if (!_immediateL) {
        
        _immediateL = [[UILabel alloc] init];
        _immediateL.textColor = Color333333;
        _immediateL.textAlignment = NSTextAlignmentLeft;
        _immediateL.font = Font(30);
        _immediateL.text = @"立即开通";
    }
    
    return _immediateL;
}

- (UIImageView *)arrowIV {
    
    if (!_arrowIV) {
    
        _arrowIV = [[UIImageView alloc] init];
        _arrowIV.contentMode = UIViewContentModeScaleAspectFit;
        _arrowIV.image = [UIImage imageNamed:@"rightArrowBG"];
    }
    
    
    return _arrowIV;
}


- (UIView *)lineV {
    
    if (!_lineV) {
        
        _lineV = [[UIView alloc] init];
        _lineV.backgroundColor = Colordddddd;
        
        
    }
    return _lineV;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
